﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RN.ERP.Web.ModelService;
using Newtonsoft.Json;
using Fly.Common.Linq;
using Fly.Common.WorkFlow;
using Telerik.Web.UI;
using Telerik.Web.UI.Skins;
using System.Text;

namespace RN.ERP.Web.Enterprise
{
    public partial class EnterpriseCorpKeyInfo :BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindAreas();
            }
        }

        protected void ListCorps_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            int pageIndex = ListCorps.CurrentPageIndex;
            int pageSize = ListCorps.PageSize;
            MakeKeyInfosCondition model = new MakeKeyInfosCondition();
            model.CorpName = txtCorpName.Text.Trim();
            model.MakeStatus = Convert.ToByte(ddlKeyInfo.SelectedValue);
            model.AreaCode = ddlAreaCode.SelectedValue;
            string condition = JsonConvert.SerializeObject(model);
            BindData(condition,pageIndex,pageSize);
        }

        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            if (e.Argument == "Rebind")
            {
                ListCorps.MasterTableView.SortExpressions.Clear();
                ListCorps.MasterTableView.GroupByExpressions.Clear();
                ListCorps.Rebind();
            }
        }

        protected void BindData(string condition,int pageIndex,int pageSize)
        {
            OrderService.OrderServiceClient client = new OrderService.OrderServiceClient();
            int count;
            var KeyInfos = client.GetMakeKeyInfos(out count, condition, pageIndex, pageSize);
            List<tb_CAPayInfo_DogID> list = JsonConvert.DeserializeObject<List<tb_CAPayInfo_DogID>>(KeyInfos);
            ListCorps.DataSource = list;
            ListCorps.VirtualItemCount = count;
        }

        private void BindAreas()
        {
            BasicService.BasicServiceClient client = new BasicService.BasicServiceClient();
            List<a_AreaSubInfo> areas = JsonConvert.DeserializeObject<List<a_AreaSubInfo>>(client.GetQu("14"));
          
            ddlAreaCode.DataValueField = "SortCode";
            ddlAreaCode.DataTextField = "Title";
            ddlAreaCode.DataSource = areas;
            ddlAreaCode.DataBind();
            ddlAreaCode.Items.Insert(0, new ListItem("全部", ""));
        }

    }
}